<template>
	<v-forms ref="formRef" :label-width="120"> </v-forms>
</template>
<script lang="ts">
import { defineComponent, ref, onMounted, reactive, toRefs, computed } from 'vue';
import VForms from '/@/components/forms/v-forms.vue';
import { validateNumber } from '/@/utils/validators';
import { ElMessage, ElMessageBox } from 'element-plus';
export default defineComponent({
	components: {
		VForms,
	},
	setup() {
		const formRef = ref();

		const state = reactive({});

		const addNew = async (data: any = {}, choiseList: any[]) => {
			
			let formList: any[] = [
				{
					type: 'input',
					key: 'name',
					label: '参数名称',
					value: data.name || '',
                    placeHolder: '请输入参数名称',
					rules: [{ required: true, message: '参数名称不能为空', trigger: ['blur', 'change'] }],
				},{
					type: 'input',
					key: 'code',
					label: '唯一编码',
                    placeHolder: '请输入唯一编码',
					value: data.code || '',
					disabledStyle: data.id? true : false,
					rules: [{ required: true, message: '唯一编码不能为空', trigger: ['blur', 'change'] }],
				},{
					type: 'radio',
					key: 'sysFlag',
					label: '系统参数',
                    placeHolder: '请输入系统参数',
					value: data.sysFlag || '',
					disabledStyle: data.id? true : false,
					rules: [{ required: true, message: '唯一编码不能为空', trigger: ['blur', 'change'] }],
                    options: [
                        {
                            value: 'Y',
                            label: '是',
                        },
                        {
                            value: 'N',
                            label: '否',
                        },
                    ],
                },
                {
					type: 'input',
					key: 'value',
					label: '参数值',
                    placeHolder: '请输入参数值',
					value: data.value || '',
					rules: [{ required: true, message: '参数值不能为空', trigger: ['blur', 'change'] }],
				},{
					type: 'select',
					key: 'groupCode',
					label: '所属分类',
                    placeHolder: '请选择所属分类',
					options: choiseList,
					disabledStyle: data.id? true : false,
					value: data.groupCode || '',
					rules: [{ required: true, message: '所属分类不能为空', trigger: ['blur', 'change'] }],
				},{
					type: 'textarea',
					key: 'remark',
					label: '备注',
                    placeHolder: '请输入备注',
					value: data.remark || '',
					rules: [{ required: false, message: '备注不能为空', trigger: ['blur', 'change'] }],
				},
			]

			if (data.id) {
				formList.push({
					type: 'input',
					label: 'id',
					key: 'id',
					show: false,
					value: data.id,
					rules: [{ required: false, message: `id不能为空`, trigger: 'change' }],
				});
			}

			let title = data.id? '编辑参数' :'新增参数'

			formRef.value.openDialog(formList, title);
		};
		return {
			formRef,
			addNew,
			...toRefs(state),
		};
	},
});
</script>

<style lang="scss" scoped>
.select-list {
	:deep(.el-form-item) {
		margin: 15px 0;
	}
}
</style>
